﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CurrentApp.cs" company="In The Hand Ltd">
//   Copyright (c) 2014-15 In The Hand Ltd, All rights reserved.
// </copyright>
// <summary>
//   Launch Store UI for the current app.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using Windows.Foundation;
using Windows.System;

namespace InTheHand.ApplicationModel.Store
{
    /// <summary>
    /// Defines methods and properties you can use to get license and listing info about the current app and perform in-app purchases.
    /// </summary>
    public static class CurrentApp
    {
        /// <summary>
        /// Gets the GUID generated by the Windows Store when your app has been certified for listing in the Windows Store.
        /// </summary>
        public static Guid AppId
        {
            get
            {
                return Windows.ApplicationModel.Store.CurrentApp.AppId;
            }
        }

        /// <summary>
        /// Creates the async operation that enables the user to view the app details.
        /// </summary>
        /// <returns></returns>
        public static IAsyncOperation<bool> RequestDetailsAsync()
        {
#if WINDOWS_APP
            LauncherOptions options = new LauncherOptions();
            options.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseMinimum;
            return Launcher.LaunchUriAsync(new Uri("ms-windows-store:PDP?PFN=" + Windows.ApplicationModel.Package.Current.Id.FamilyName), options);
#elif WINDOWS_PHONE_APP
            return Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:navigate?appid=" + AppId));
#else
            return Windows.System.Launcher.LaunchUriAsync(new Uri("zune:navigate?appid=" + AppId));
#endif
        }

        /// <summary>
        /// Creates the async operation that enables the user to review the current app.
        /// </summary>
        /// <returns></returns>
        public static IAsyncOperation<bool> RequestReviewAsync()
        {
#if WINDOWS_APP
            LauncherOptions options = new LauncherOptions();
            options.DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseMinimum;
            return Launcher.LaunchUriAsync(new Uri("ms-windows-store:REVIEW?PFN=" + Windows.ApplicationModel.Package.Current.Id.FamilyName), options);
#elif WINDOWS_PHONE_APP
            return Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid=" + AppId));
#else
            return Windows.System.Launcher.LaunchUriAsync(new Uri("zune:reviewapp?appid=app" + AppId));
#endif
        }
    }
}
